﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Wpf2.RelayCommand
{
    class RelayCommand<T> : ICommand
    {
        private readonly Action<T> _excuted;
        private readonly Predicate<T> _canExcuted;

        public RelayCommand(Predicate<T> canExcuted, Action<T> excuted)
        {
            if (excuted == null)
                throw new ArgumentNullException("func excuted is null");
            _excuted = excuted;
            _canExcuted = canExcuted;
        }


        public bool CanExecute(object parameter)
        {
            return _canExcuted == null ? true : _canExcuted((T)parameter);
        }


        public void Execute(object parameter)
        {
            _excuted((T)parameter);
        }

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }
    }

}
